// verb_convert.cpp : Defines the entry point for the console application.
//

/*
Convert realtek verb table from Assemble format to C format

1. convert ';' to "// ;"
2. convert "dd NNNNNNNNh" to "0xNNNNNNNN,"
*/
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

void help(void)
{
	printf("Utility to convert Realtek audio verb table from assembly to C format.\n\
    VerbCVT.exe <inputfile> <outputfile>\n");
}

void Asm2C(FILE *fp1, FILE *fp2)
{
	char c;
	char buffer[80] = {0};
	unsigned long i;

	while((c = fgetc(fp1)) != EOF)
	{
		if (c == ';')
		{
			fputc('/', fp2);
			fputc('/', fp2);
			fputc(' ', fp2);
			fputc(c, fp2);
		}
		else if ((c == 'd') &&(( c = fgetc(fp1)) == 'd'))
		{
			fscanf(fp1, " %08lXh", &i);
			fprintf(fp2, "0x%08lX,", i);
		}
		else
		{
			fputc(c, fp2);
		}
	}
}

int main(int argc, char *argv[])
{
	FILE *fp1, *fp2;

	if (argc != 3)
	{
		help();
		return 1;
	}

	if ((fp1 = fopen(argv[1], "rb")) == NULL)
	{
		printf("Can't open file %s!\n", argv[1]);
		return 2;
	}

	if ((fp2 = fopen(argv[2], "wb")) == NULL)
	{
		printf("Can't open file %s!\n", argv[2]);
		return 3;
	}

	Asm2C(fp1, fp2);

	fclose(fp1);
	fclose(fp2);
	fp1 = NULL;
	fp2 = NULL;

	return 0;
}

